<template>
  <PageWrapper dense contentFullHeight contentClass="flex bg-white">
    <feed-type-tree class="w-1/4 xl:w-1/5" @select="handleSelect" />
    <BasicTable
      ref="tableRef"
      @register="registerTable"
      class="w-3/4 xl:w-4/5"
      :searchInfo="searchInfo"
    >
      <!--      <template #toolbar>
        <a-button type="primary" @click="handleCreate">新增做法</a-button>
      </template>-->
      <template #action="{ record }">
        <TableAction
          :actions="[
            {
              label: '查看',
              icon: 'clarity:eye-show-solid',
              title: '查看用户详情',
            },
            {
              icon: 'clarity:note-edit-line',
              title: '编辑用户资料',
              onClick: handUnitEditDrawer.bind(null, record),
            },
            {
              icon: 'ant-design:delete-outlined',
              color: 'error',
              title: '删除此账号',
              popConfirm: {
                title: '是否确认删除',
              },
            },
          ]"
        />
      </template>
    </BasicTable>
  </PageWrapper>
</template>

<script lang="ts">
  import { defineComponent, reactive, ref, unref } from 'vue';
  import { BasicTable, TableAction, TableActionType, useTable } from '/@/components/Table';
  import { PageWrapper } from '/@/components/Page';
  import { columns, searchFormSchema } from './practice.data';
  import FeedTypeTree from './FeedTypeTree.vue';
  import { getListPage } from '/@/api/cuisine/practice';

  export default defineComponent({
    name: 'Index',
    components: { BasicTable, PageWrapper, TableAction, FeedTypeTree },
    setup() {
      const searchInfo = reactive<any>({});

      function handleSelect(pid: number) {
        searchInfo.type = 2;
        searchInfo.pid = pid;
        reload();
      }

      function handleSuccess() {
        reload();
      }

      const [registerTable, { reload, updateTableDataRecord }] = useTable({
        title: '做法列表',
        rowKey: 'id',
        rowSelection: { type: 'checkbox' },
        api: getListPage,
        columns,
        dataSource: [],
        formConfig: {
          labelWidth: 120,
          schemas: searchFormSchema,
        },
        useSearchForm: true,
        showTableSetting: true,
        bordered: true,
        beforeFetch(info) {
          info.type = 2;
          return info;
        },
        handleSearchInfoFn(info) {
          info.type = 2;
          return info;
        },
      });
      const tableRef = ref<Nullable<TableActionType>>(null);

      function getTableAction() {
        const tableAction = unref(tableRef);
        if (!tableAction) {
          throw new Error('tableAction is null');
        }
        return tableAction;
      }

      function getSelectRowList() {
        return getTableAction().getSelectRows();
      }
      return {
        handleSelect,
        searchInfo,
        registerTable,
        handleSuccess,
        getSelectRowList,
        tableRef,
      };
    },
  });
</script>

<style scoped></style>
